package com.yun.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.dao.NavMapper;
import com.yun.pojo.Nav;
import com.yun.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NavServiceImpl extends ServiceImpl<NavMapper, Nav> implements NavService {
    //动态获取菜单列表
    @Autowired
    private NavMapper navMapper;

    /**
     * 查询二级菜单
     * 查询条件 :一级菜单parent_id = 0;
     *          二级菜单parent_id = 一级菜单id
     *
     * */
    @Override
    public List<Nav> findRightsList() {
        QueryWrapper<Nav> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id" , 0);
        List<Nav> navs_0 = navMapper.selectList(queryWrapper);
        for (Nav nav : navs_0) {
            queryWrapper.clear();
            queryWrapper.eq("parent_id" , nav.getId());
            List<Nav> rights_1 = navMapper.selectList(queryWrapper);
            nav.setChildren(rights_1);
        }
        return navs_0;
    }
}
